package main

import (
	"bytes"
	"fmt"
)

//AES对称加密，不足128位用0补充

func zeroPadding(cipherText []byte, blockSize int) []byte {
	padding := blockSize - len(cipherText)%blockSize //填充的长度
	padText := bytes.Repeat([]byte{'*'}, padding)    //填充0
	return append(cipherText, padText...)            //字节叠加
}
func zeroUnPadding(origData []byte) []byte { //删除填充数据

	return bytes.TrimRightFunc(origData, func(r rune) bool {
		return r == rune('*')
	})
}

func main() {

	mystr := "123456789"
	newStr := string(zeroPadding([]byte(mystr), 20))
	fmt.Println("newStr len is :", len(newStr))
	fmt.Printf("newStr value is:%v \n ", newStr)

	reMystr := zeroUnPadding([]byte(newStr))
	fmt.Println("reMystr len is :", len(reMystr))
	fmt.Printf("reMystr value is:%v \n ", string(reMystr))

}
